var statusLists = [
    {
        id: '2',
    text: '退款申请'
    },{
    id: '1',
    text: '处理中'
}, {
    id: '4',
    text: '退款成功'
}, {
    id: '5',
    text: '退款失败'
}];
var ns, toast;
var app = new Vue({
    el: '#app',
    data: {
        List: [],
        statusList: this.statusLists,
        getdata_timeout: null,
        statuscount:[],
        // orderlist: [],
        // statusList:[],
        orderCount: 0,
        status: '2',
        total: {
            ProcessCount: 0,
        },
        pageindex: 0,
        pagesize: 10,
        is_searching:false,
        can_scroll:false,
        current_item_length: 0,
    },
    methods: {
        get_data: function() {
            var that = this;
            that.is_searching = true;
            that.can_scroll = false;
            var opt = {
                action: 'getrefundorderlist',
                Status: that.status,
                startRowIndex: that.pageindex,
                pageSize: that.pagesize,
            };
            ns.post(opt, function(succeed, data, err) {
                that.is_searching = false;
                if (succeed) {
                    if(data.status){
                        if (data.data.length == that.pagesize) {
                            that.can_scroll = true;
                        }
                        if (that.pageindex == 0) {
                            that.List = data.data;
                        } else {
                            that.List = that.List.concat(data.data);
                        }
                        that.current_item_length = that.List.length;

                        // that.List = data.data;


                    }
                } else if (err) {
                    that.List = [];
                    that.current_item_length = 0;
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            })
        },

        //导航栏切换
        randomSwitchBtn: function(name, id, index) {
            var that = this;
            that.pageindex=0;
            //调用接口给数据赋值
            that.status = id;
            that.orderCount = "";
            that.total.ProcessCount = "";
            that.get_data();

        },
        //订单详情
        open_order_detail: function(id) {
            var that = this;
            ns.openWin('dl_order_detail', '订单详情', {
                id: id,
            });
        },
        //重新退款
        reback_price:function(id){
            var that=this;
            that.$dialog.confirm({
                title: '提示信息',
                message: '确定要重新发起退款吗？',
                confirmButtonText:'确认',
                cancelButtonText:'取消',
            }).then(() => {
                var option = {};
                option.OrderID=id;
                option.action = "acceotorderrefund";
                ns.post(option, function(succeed, data, err) {
                    if (succeed) {
                        if(data.status){
                            api.toast({
                                msg: '操作成功',
                                duration: 2000,
                                location: 'bottom'
                            });
                        }else{
                            api.toast({
                                msg: data.Msg,
                                duration: 2000,
                                location: 'bottom'
                            });
                        }
                        that.get_data();
                    }else{
                        api.toast({
                            msg: '操作失败',
                            duration: 2000,
                            location: 'bottom'
                        });
                    }
                 });

            }).catch(() => {
            });
        },
        // 同意退款
        back_price:function(id,price){
            var that=this;
            that.$dialog.confirm({
                title: '提示信息',
                message: '本次退款金额为【￥'+price+'】元，确定要进行退款操作吗？',
                confirmButtonText:'确认',
                cancelButtonText:'取消',
            }).then(() => {
                var option = {};
                option.OrderID=id;
                option.action = "acceotorderrefund";
                ns.post(option, function(succeed, data, err) {
                    if (succeed) {
                        if(data.status){
                            that.$dialog.alert({
                                title: '提示信息',
                                message: '退款已提交至收款平台处理，一般24小时内退款至付款账户',
                                theme: 'round-button',
                              }).then(() => {
                                // on close
                              });
                            // api.toast({
                            //     msg: '操作成功',
                            //     duration: 2000,
                            //     location: 'bottom'
                            // });
                        }else{
                            api.toast({
                                msg: data.Msg,
                                duration: 2000,
                                location: 'bottom'
                            });
                        }
                        that.get_data(true);
                    }else{
                        api.toast({
                            msg: '操作失败',
                            duration: 2000,
                            location: 'bottom'
                        });
                    }
                 });

            }).catch(() => {
            });
        },
        //确认收货
        sure_save:function(id){
            var that = this;
            that.$dialog.confirm({
                title: '提示信息',
                message: '请确认是否已经收到退回的商品？',
                confirmButtonText:'确认收到',
                cancelButtonText:'没有收到',
            }).then(() => {
                var option = {};
                option.ID=id;
                option.action = "confirmacceptgoods";
                ns.post(option, function(succeed, data, err) {
                    if (succeed) {
                        if(data.status){
                            api.toast({
                                msg: '操作成功',
                                duration: 2000,
                                location: 'bottom'
                            });
                        }else{
                            api.toast({
                                msg: data.Msg,
                                duration: 2000,
                                location: 'bottom'
                            });
                        }
                        that.get_data(true);
                    }else{
                        api.toast({
                            msg: '操作失败',
                            duration: 2000,
                            location: 'bottom'
                        });
                    }
                 });

            }).catch(() => {
            });

        },
        //退款进度
        do_openstep:function(id){
            var that = this;
            ns.openWin('messageDetail', '退款进度',{
                id:id,
                headerbg:2,
            });
        },
        //订单关闭
        open_order_Close: function(id) {
            var that = this;

            api.confirm({
                    title: '提示',
                    msg: '确定关闭?',
                    buttons: ['确定', '取消']
                }, function(ret, err) {
                  if (ret.buttonIndex == 1) {
                    //调用关闭接口
                    var opt = {
                        action: 'uporderstatus', //关闭的方法名
                        orderid: id,
                        orderstatus: 4
                    };
                    ns.post(opt, function(succeed, data, err) {
                        if (succeed) {
                            api.toast({
                                msg: '操作成功！',
                                duration: 2000,
                                location: 'bottom'
                            });
                              app.get_data(true);
                        } else if (err) {
                            api.toast({
                                msg: err,
                                duration: 2000,
                                location: 'bottom'
                            });
                        }

                    })

                  }


            });

        },
        //拒绝退款
        open_noback:function(id){
            var that=this;
            ns.openWin('back_order_no', '拒绝退款',{
                id:id
            });
        },
        // 打电话
        tel_phone: function(phone) {
            api.call({
                type: 'tel_prompt',
                number: phone
            });
        },

    set_status_bar: function () {
        var that = this;
        api.setStatusBarStyle({
            style: 'dark',
            color: 'transparent'
        });
    }
}
});

apiready = function() {
    api.parseTapmode();
    app.set_status_bar();
    ns = window.Foresight.Util;
    ns.init_pull();
    app.get_data();


    api.addEventListener({
        name: 'onlogin'
    }, function(ret, err) {
        app.get_data();
    });
    api.addEventListener({
        name: 'shopmsgevent'
    }, function(ret, err){
          app.get_data();
    });
    api.addEventListener({
        name: 'do_open_search'
    }, function(ret, err) {
        ns.openWin('search_frm', '搜索');
    });
    api.addEventListener({
        name: 'do_open_saixuan'
    }, function(ret, err) {
        
    });

}
